﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace mediaPrime.Plugin.TV
{
    /// <summary>
    /// Interaktionslogik für MainUserInterface.xaml
    /// </summary>
    public partial class MainUserInterface : UserControl
    {
        private TVPlugin tvPlugin;

        public MainUserInterface(TVPlugin tvPlugin)
        {
            InitializeComponent();

            this.tvPlugin = tvPlugin;

            this.Loaded += MainUserInterface_Loaded;
            this.PreviewKeyDown += MainUserInterface_PreviewKeyDown;
        }

        void MainUserInterface_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                e.Handled = true;
                showChannelList();
            }
        }

        void MainUserInterface_Loaded(object sender, RoutedEventArgs e)
        {
            Keyboard.Focus(this);
        }

        private void showChannelList()
        {
            var dlg = new Dialogs.ChannelList();
            dlg.LoadChannels(tvPlugin.SelectedTVServerProvider.GetChannelList());

            dlg.ShowDialog();
        }
    }
}
